package cluster.kmeans.old;

import java.util.Vector;
class Cluster {
	private String mName ;
	private Centroid mCentroid;
	private double mSumSqr;
	
	private Vector mDataPoints;
	
	@SuppressWarnings("rawtypes")
	public Cluster(String name) {			
		this.mName = name;
		this.mCentroid = null; //will be set by calling setCentroid()  	
		mDataPoints = new Vector();
	}
	
    /**
	 * @return the mCentroid
	 */
	public Centroid getCentroid() {
		return mCentroid;
	}
	/**
	 * @param mCentroid the mCentroid to set
	 */
	public void setCentroid(Centroid mCentroid) {
		this.mCentroid = mCentroid;
	}
	
	public void addDataPoint(DataPoint dp) { 
	//called from CAInstance      
	 dp.setCluster(this); 
	//initiates a inner call to calc EuclideanDistance() in DP.   
	this.mDataPoints.addElement(dp);      
	  calcSumOfSquares();   
	}
    public void removeDataPoint(DataPoint dp) { 
 this.mDataPoints.removeElement(dp);  
  calcSumOfSquares();    }
    public int getNumDataPoints() {  
return this.mDataPoints.size();    }
    public DataPoint getDataPoint(int pos) { 
  return (DataPoint)
		this.mDataPoints.elementAt(pos);  
		  }
    public void calcSumOfSquares() { 
	//called from Centroid       
	int size = this.mDataPoints.size();       
	double temp = 0;        
	for (int i = 0; i < size; i++) {    
		        temp = temp + ((DataPoint)this.mDataPoints.elementAt(i)).getCurrentEuDt();   
		     }      
		  this.mSumSqr = temp;    }
}
    public double getSumSqr() { 
	       return this.mSumSqr;    }
    public String getName() {   
	     return this.mName;    }
    public Vector getDataPoints() {  
	      return this.mDataPoints;    }
}